<?php

/**
 * This is the model class for table "back_accounts".
 *
 * The followings are the available columns in table 'back_accounts':
 * @property integer $id
 * @property integer $back_accounts_no
 * @property string $location
 * @property string $period_covered_start
 * @property string $period_covered_end
 * @property integer $total_accts
 * @property string $remarks
 * @property string $unit_assignment
 * @property string $duty_status
 * @property integer $employee_id
 * @property integer $main_ledger_id
 *
 * The followings are the available model relations:
 * @property Employee $employee
 * @property MainLedger $mainLedger
 */
class BackAccounts extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return BackAccounts the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'back_accounts';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('location, period_covered_start, employee_id, main_ledger_id', 'required'),
			array('back_accounts_no, total_accts, employee_id, main_ledger_id', 'numerical', 'integerOnly'=>true),
			array('location, unit_assignment, duty_status', 'length', 'max'=>45),
			array('period_covered_end, remarks', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, back_accounts_no, location, period_covered_start, period_covered_end, total_accts, remarks, unit_assignment, duty_status, employee_id, main_ledger_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'employee' => array(self::BELONGS_TO, 'Employee', 'employee_id'),
			'mainLedger' => array(self::BELONGS_TO, 'MainLedger', 'main_ledger_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'back_accounts_no' => 'Back Accounts No',
			'location' => 'Location',
			'period_covered_start' => 'Period Covered Start',
			'period_covered_end' => 'Period Covered End',
			'total_accts' => 'Total Accts',
			'remarks' => 'Remarks',
			'unit_assignment' => 'Unit Assignment',
			'duty_status' => 'Duty Status',
			'employee_id' => 'Employee',
			'main_ledger_id' => 'Main Ledger',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('back_accounts_no',$this->back_accounts_no);
		$criteria->compare('location',$this->location,true);
		$criteria->compare('period_covered_start',$this->period_covered_start,true);
		$criteria->compare('period_covered_end',$this->period_covered_end,true);
		$criteria->compare('total_accts',$this->total_accts);
		$criteria->compare('remarks',$this->remarks,true);
		$criteria->compare('unit_assignment',$this->unit_assignment,true);
		$criteria->compare('duty_status',$this->duty_status,true);
		$criteria->compare('employee_id',$this->employee_id);
		$criteria->compare('main_ledger_id',$this->main_ledger_id);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}